#include "Train.h"

class Solution {
public:
    ListNode* reverseList(ListNode* head) {
        ListNode* cur = head, * newhead = nullptr;
        while (cur) {
            ListNode* next = cur->next;
            cur->next = newhead;
            newhead = cur;
            cur = next;
        }
        return newhead;
    }
};


class Solution {
public:
    
    ListNode* reverseList(ListNode* head) {
        if (head == nullptr || head->next == nullptr)  return head;
        ListNode* newhead = reverseList(head->next);
        head->next->next = head; //头的下一个节点的下一个节点指向自己
        head->next = nullptr;
        return newhead;
    }
};